import http from './base.request.js';

const apiPost = {
	post(url, data) {
		return http.request({
			url: url,
			data: data
		}).then(function(data) {
			let [error, res] = data;
			if (error) {
				return Promise.reject(error);
				uni.showToast({
					icon: 'none',
					title: '请求接口失败失败'
				});
			}
			if (res.data.code == 0) {
				uni.showToast({
					icon: 'none',
					title: res.data.msg
				});
				return Promise.resolve(res.data);
			}else{
				return Promise.resolve(res.data);
			}
		})
	},
	upload(url, fromdata, path, name) {
		return http.uploadFile({
			url: url,
			formData: fromdata,
			filePath: path,
			name: name
		}).then(function(data) {
			let [error, res] = data;
			if (error) {
				return Promise.reject(error);
			}
			if (res.statusCode === 200) {
				return Promise.resolve(JSON.parse(res.data));
			} else {
				return Promise.reject(error);
			}
		})
	}
}

export default apiPost
